package org.ramoths.netcom.outils;

import java.io.IOException;
import java.io.OutputStream;

public class FluxSortieObjet extends OutputStream
{
	private byte[] donnees;
	private int taille;
	
	public FluxSortieObjet()
	{
		this.donnees = new byte[1024];
		this.taille = 0;
	}
	
	@Override
	public void write(int b) throws IOException
	{
		if (donnees.length == taille)
		{
			byte[] tmp = new byte[donnees.length + 1024];
			System.arraycopy(donnees, 0, tmp, 0, donnees.length);
			donnees = tmp;
		}
		donnees[taille++] = (byte) b;
	}
	
	@Override
	public void close() throws IOException
	{
		if (donnees.length != taille)
		{
			byte[] tmp = new byte[taille];
			System.arraycopy(donnees, 0, tmp, 0, taille);
			donnees = tmp;
		}
	}
	
	public byte[] getDonnees()
	{
		return donnees;
	}
}
